package com.kuaiying.kuai.ying.model.yangzhengma;

import java.text.SimpleDateFormat;
import java.util.Date;

import com.jfinal.plugin.activerecord.Model;
import com.jfinal.plugin.activerecord.Page;
import com.kuaiying.kuai.ying.model.print_shop.PrintshopModel;
import com.kuaiying.kuai.ying.model.user.UserModel;

public class YangzhengmaModel extends Model<YangzhengmaModel>{

	private static final long serialVersionUID = -6984293973714614241L;
	
	public static final YangzhengmaModel me = new YangzhengmaModel();
	
	private static final String USER_CACHE = "shop";
	
	public YangzhengmaModel(){
		super( );
	}
	/**
	 * 所有 sql 与业务逻辑写在 Model 或 Service 中，不要写在 Controller 中，养成好习惯，有利于大型项目的开发与维护
	 */
	public Page<YangzhengmaModel> paginate(int pageNumber, int pageSize) {
		return paginate(pageNumber, pageSize, "select *", "from   order by id asc");
	}
	
	/**
	 * 根據用戶名和用戶密碼驗證用戶是否存在
	 * @param userName：用戶名
	 * @param pwd：用戶密碼
	 * @return：用戶信息或null
	 */
	public YangzhengmaModel findByPN(String phonenumber){
		try{
		    String sql = "select * from yanzhengma where phonenum = '" + phonenumber + "'" ;
		    System.out.println( sql );
		    YangzhengmaModel user = me.findFirst(sql);
		    return user;
		}catch (Exception e){
			return null;
		}
	}
	
	public boolean upadteshop_lastlogintime(Integer shop_id) {
		YangzhengmaModel shop = YangzhengmaModel.me.findById(shop_id);
		String last_login_time = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format( new Date());
		shop.set("last_use_time", last_login_time);
		return shop.update();
	}
}


